package kam.fire;

import java.io.Serializable;
import java.util.ArrayList;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;


@SuppressWarnings("serial")
@JsonRootName(value = "rooms")
public class Room implements Comparable<Room>, Serializable {

	DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
	private String name;
	private String topic;
	@JsonProperty("created_at")
	private String dateCreated;
	@JsonProperty("updated_at")
	private String dateUpdated;
	private int Id;
	private int Index;
	@JsonProperty("membership_limit")
	private int limit;
	private boolean locked;
	private boolean full;
	private boolean open;
	private ArrayList<Message> messages = new ArrayList<Message>();
	private int messagesPosted;

	private int userIndex;
	User user = new User();

	public int getIndex() {
		return Index;
	}

	public void setIndex(int Index) {
		this.Index = Index;
	}

	public int getUserIndex() {
		return userIndex;
	}

	public void setUserIndex(int userIndex) {
		this.userIndex = userIndex;
	}

	public ArrayList<Message> getMessages() { // obsolete
		return messages;
	}

	public Message getMessage(int num) { // obsolete
		return messages.get(num);
	}

	public void addMessagePosted() { // obsolete
		messagesPosted++;
	}

	public int getMessagesPosted() { // obsolete
		return messagesPosted;
	}

	public void resetMessagesPosted() { // obsolete
		messagesPosted = 0;
	}

	public void addMessage(Message message) { // obsolete
		messages.add(message);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name.trim();
	}

	public String getTopic() {
		return topic;
	}

	public void setTopic(String topic) {
		this.topic = topic.trim();
	}

	public int getId() {
		return Id;
	}

	public void setId(int Id) {
		this.Id = Id;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public boolean getLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		locked = this.locked;
	}

	public boolean getFull() {
		return full;
	}

	public void setFull(boolean full) {
		this.full = full;
	}

	public boolean getOpen() {
		return this.open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}

	public String getDateCreated() {
		return dateCreated;
	}

	public void setDate(String date) {
		dateCreated = date;
	}

	public String getDateUpdated() {
		return dateUpdated;
	}

	public void setDateUpdated(String date) {
		dateUpdated = date;
	}

	public Room copy() {
		Room copy = new Room();
		copy.name = name;
		copy.topic = topic;
		copy.dateCreated = dateCreated;
		copy.dateUpdated = dateUpdated;
		copy.Id = Id;
		copy.limit = limit;
		copy.full = full;
		copy.open = open;
		return copy;
	}

	@Override
	public String toString() {
		return name;
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Room other = (Room) obj;
		return this.getId()==other.getId();
		
	}

	public int compareTo(Room another) {
		if (another == null)
			return 1;
		return another.dateCreated.compareTo(dateCreated);
	}
}
